<script type="text/javascript" src="/media/js/validate.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        
        $("#form").validate({
            rules:{
                name:'required',
                fieldname:'required',
                value:'required',
                position:'number'
            },
            messages:{
                name:'分类名称不能为空！',
                position:'请添写正确的数字格式！',
                value:"字段值不能为空",
                fieldname:'字段名不能为空'
            },
            invalidHandler: function(e, validator) {
                var errors = validator.numberOfInvalids();
                if (errors) {
                    var message = errors == 1
                        ? '您有<font color="green">1</font>处填写错误,请认真填写！'
                    : '您有 <font color="green">' + errors + ' </font>处填写错误,请认真填写！';
                    $("div.error #error-info").html(message);
                    $('div.success').hide();
                    $("div.error").show();
                } else {
                    $("div.error").hide();
                }
            }
        });
        
        $('#field-value').html('<input name="value" id="value" class="text medium"  value="<?php echo $data['value'] ?>"/>');
        
        
         if($("input[name]=type").is(':checked')){
            if($("input:checked").val() == 'strings') {
                $('#field-value').html('<textarea name="value" id="value" class="textarea" style="width:500px;height:100px;"><?php echo $data['value'] ?></textarea>');
            } else if($("input:checked").val() == 'bool') {
                $('#field-value').html('<input class="radio" type="radio" <?php if($data['value'] == 1):?>checked="checked"<?php endif?> value="1" name="value">'+
                    '是<input class="radio" type="radio" value="0" name="value" <?php if($data['value'] == 0):?>checked="checked"<?php endif?>>'+
                    '否');
            } else {
                $('#field-value').html('<input name="value" id="value" class="text medium "  value="<?php echo $data['value'] ?>"/>');
            }
        }
        
        
        $("input[name]=type").click(function() {
            if($(this).is(':checked')){
                if($(this).val() == 'strings') {
                    $('#field-value').html('<textarea name="value" id="value" class="textarea" style="width:500px;height:100px;"><?php echo $data['value'] ?></textarea>');
                } else if($(this).val() == 'bool') {
                    $('#field-value').html('<input class="radio" type="radio" <?php if($data['value'] == 1):?>checked="checked"<?php endif?> value="1" name="value">'+
                        '是<input class="radio" type="radio" value="0" name="value" <?php if($data['value'] == 0):?>checked="checked"<?php endif?>>'+
                        '否');
                } else {
                    $('#field-value').html('<input name="value" id="value" class="text medium"  value="<?php echo $data['value'] ?>"/>');
                }
            }
        });
        
        
        
        
    });
</script>
<div id="page-layout"><div id="page-content">
        <div id="page-content-wrapper" >
            <div class="hastable">
                <div class="inner-page-title">
                    <h2>分类管理</h2>
                </div>
                <?php echo Message::get(); ?>
                <div class="response-msg error ui-corner-all" style="display:none;">
                    <span>错误提示</span><span id="error-info"></span>
                </div>
                <div class="two-column">
                    <div style="width: 100%;float: right;">
                        <div class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all">
                            <div class="portlet-header ui-widget-header">编辑内容<span class="ui-icon ui-icon-circle-arrow-s"></span></div>

                            <div class="portlet-content">

                                <form action="<?php echo URL::base() . 'admin/config/add'; ?>" method="post" enctype="multipart/form-data" class="forms" name="form" id="form">
                                    <ul>
                                        <li>
                                            <label for="fieldname" class="desc">字段名<span class="req">*</span></label>
                                            <input name="fieldname" id="fieldname" class="text" type="text" value="<?php echo $data['fieldname'] ?>" disabled="disabled"/>
                                        </li>
                                        <li>
                                            <label for="name" class="desc">字段值说明<span class="req">*</span></label>
                                            <input name="name" id="name" class="text medium"  value="<?php echo $data['name'] ?>"/>
                                        </li>

                                        <li>
                                            <label for="type" class="desc">参数类型</label>
                                            <span><input class="radio" type="radio" value="string" checked="checked" name="type" <?php if($data['type'] == 'string'):?>checked="checked"<?php endif?>>
                                            <font>文本</font></span>
                                            <input class="radio" type="radio" value="bool" name="type" <?php if($data['type'] == 'bool'):?>checked="checked"<?php endif?>>
                                            <font> 布尔</font>
                                            <input class="radio" type="radio" value="number" name="type" <?php if($data['type'] == 'number'):?>checked="checked"<?php endif?>>
                                            <font>数字</font>
                                            <input class="radio" type="radio" value="strings" name="type" <?php if($data['type'] == 'strings'):?>checked="checked"<?php endif?>>
                                            <font> 多行文本</font>
                                        </li>
                                        <li>
                                            <label for="value" class="desc">字段值<span class="req">*</span></label>
                                            <div id="field-value">


                                            </div>
                                        </li>

                                    </ul>
                                    <ul>
                                        <li class="buttons" style=" text-align: center;">
                                            <button class="ui-state-default ui-corner-all ui-button" type="submit" id="submit_btn">  添加分类</button>
                                        </li>
                                    </ul>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <div class="clear"></div>

            <?php echo View::factory('admin/system/system_left')->render(); ?>

            <div class="clear"></div>
        </div>
        <div class="clear"></div>
    </div>
    <div class="clear"></div>	